

using Backend;
using System.Collections.Generic;

namespace BusinessTier
{
    public class Edge
    {
        private Vertex _from;
        private Vertex _to;
        private List<Leg> legs;



        public Edge(Vertex from, Vertex to)
        {
            this._from = from;
            this._to = to;
            legs = new List<Leg>();
        }

        public Vertex From
        {
            get
            {
                return _from;
            }
        }

        public Vertex To
        {
            get
            {
                return _to;
            }
        }

        public List<Leg> Legs
        {
            get { return legs; }
            set { legs = value; }
        }

        public void addLeg(Leg leg)
        {
            if (!containsLeg(leg))
                legs.Add(leg);
        }


        public void removeLeg(Leg leg)
        {
            legs.Remove(leg);


        }



        public bool containsLeg(Leg paramLeg)
        {
            foreach (Leg leg in legs)
            {
                if (paramLeg.Id == leg.Id)
                    return true;
            }


            return false;
        }

        public double lowestPrice()
        {
            if (legs.Count != 0)
            {

                double price = legs[0].Price;

                foreach (Leg leg in legs)
                    if (leg.Price < price)
                        price = leg.Price;

                return price;

            }

            else
                return -1;
        }

        public Leg getLegWithLowestPrice()
        {


            if (legs.Count != 0)
            {
                Leg legWithLowestPrice = legs[0];
                foreach (Leg leg in legs)
                {
                    if (leg.Price < legWithLowestPrice.Price)
                        legWithLowestPrice = leg;
                }

                return legWithLowestPrice;
            }

            else
                return null;
        }
    }

}